import { createStore } from 'vuex'

export default createStore({
  state: {
    userId: null,
    orderList: [],
  },
  mutations: {
    // 登录成功存下用户id
    reviseUserId(state, payload) {
      // console.log('商店reviseUserId函数执行了',payload.status);
      state.userId = payload.status
    },
    // 储存用户订单信息
    setUserOrderList(state, payload) {
      state.orderList = payload.orderList
    }
  },
  getters: {
    filterProductList: (state) => {
      // console.log('filter',state);
      return (type) => {
        let res = []
        console.log('filter触发', type);
        if(type=="全部订单") return state.orderList
        for (let i = 0; i < state.orderList.length; i++) {
          if (state.orderList[i].type == type) {
            res.push(state.orderList[i])
          }
        }
        return res
      }
    }
  }

})